<%@ page language="java" pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="org.logicalcobwebs.proxool.ConnectionPoolDefinitionIF"%>
<%@ page import="org.logicalcobwebs.proxool.ProxoolFacade"%>
<%@ page import="org.logicalcobwebs.proxool.admin.SnapshotIF"%>
<%@ page import="org.logicalcobwebs.proxool.ConnectionInfoIF"%>
<%@ page import="org.jawa.core.database.DbConnectionManager"%>
<jsp:useBean id="webManager" class="org.jawa.admin.util.WebManager" />
<%
	webManager.init(request, response, session, application, out);
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>数据库属性</title>
		<meta name="pageID" content="1106" />
	</head>
	<body>
		<div class="row-fluid">
			<ul class="breadcrumb">
				<li>
					您现在的位置:
				</li>
				<li>
					<a href="<%=path%>/admin/index.jsp">服务器</a>
				</li>
				<li>
					<span class="divider">/</span>
				</li>
				<li class="active">
					数据库属性
				</li>
			</ul>
			<div class="page-header">
				<h3>
					数据库属性
				</h3>
			</div>

			<%
				Connection con = null;
				try {
					con = DbConnectionManager.getConnection();
					DatabaseMetaData metaData = con.getMetaData();
			%>
			<fieldset>
				<legend>
					数据库
				</legend>
				<table class="table table-striped table-bordered ">
					<tbody>
						<tr>
							<th>
								数据库和版本:
							</th>
							<td>
								<%=metaData.getDatabaseProductName()%>
								<%=metaData.getDatabaseProductVersion()%>
							</td>
						</tr>
						<tr>
							<th>
								JDBC 驱动程序:
							</th>
							<td>
								<%=metaData.getDriverName()%>
							</td>
						</tr>
						<tr>
							<th>
								JDBC 驱动程序版本：
							</th>
							<td>
								<%=metaData.getDriverVersion()%>
							</td>
						</tr>
						<tr>
							<th>
								DB 连接 URL：
							</th>
							<td>
								<%=metaData.getURL()%>
							</td>
						</tr>
						<tr>
							<th>
								DB 用户：
							</th>
							<td>
								<%=metaData.getUserName()%>
							</td>
						</tr>
						<tr>
							<th>
								事务支持：
							</th>
							<td>
								<%=(metaData.supportsTransactions()) ? "支持" : "不支持"%>
							</td>
						</tr>
						<tr>
							<th>
								事务隔离级别：
							</th>
							<td>
								<%
									if (con.getTransactionIsolation() == Connection.TRANSACTION_NONE) {
								%>
								TRANSACTION_NONE
								<%
									} else if (con.getTransactionIsolation() == Connection.TRANSACTION_READ_COMMITTED) {
								%>
								TRANSACTION_READ_COMMITTED
								<%
									} else if (con.getTransactionIsolation() == Connection.TRANSACTION_READ_UNCOMMITTED) {
								%>
								TRANSACTION_READ_UNCOMMITTED
								<%
									} else if (con.getTransactionIsolation() == Connection.TRANSACTION_REPEATABLE_READ) {
								%>
								TRANSACTION_REPEATABLE_READ
								<%
									} else if (con.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE) {
								%>
								TRANSACTION_SERIALIZABLE
								<%
									}
								%>
							</td>
						</tr>
						<tr>
							<th>
								支持一次打开多连接：
							</th>
							<td>
								<%=(metaData.supportsMultipleTransactions()) ? "支持" : "不支持"%>

							</td>
						</tr>
						<tr>
							<th>
								在只读方式中：
							</th>
							<td>
								<%=(metaData.isReadOnly()) ? "是" : "否"%>
							</td>
						</tr>
					</tbody>
				</table>
			</fieldset>
			<%
				} finally {
					try {
						if (con != null) {
							con.close();
						}
					} catch (SQLException e) {

					}
				}

				if (DbConnectionManager.getConnectionProvider().isPooled()) {
					try {
						// Get metadata about the connection pool
						ConnectionPoolDefinitionIF poolDef = ProxoolFacade.getConnectionPoolDefinition("jawa");
						SnapshotIF poolStats = ProxoolFacade.getSnapshot("jawa", true);
						Integer active = 100 * poolStats.getActiveConnectionCount() / poolStats.getMaximumConnectionCount();
						Integer inactive = 100
								* (poolStats.getAvailableConnectionCount() - poolStats.getActiveConnectionCount())
								/ poolStats.getMaximumConnectionCount();
						Integer notopened = 100 - active - inactive;
						SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
			%>
			<fieldset style="">
				<legend>
					连接池
				</legend>
				<table class="table table-striped table-bordered ">
					<tbody>
						<tr>
							<th>
								House Keeping Interval:
							</th>
							<td>
								<%=(poolDef.getHouseKeepingSleepTime() / 1000)%>
								秒
							</td>
						</tr>
						<tr>
							<th>
								连接最大生命时间:
							</th>
							<td>
								<%=(poolDef.getMaximumConnectionLifetime() / 1000)%>
								秒
							</td>
						</tr>
						<tr>
							<th>
								最小连接数:
							</th>
							<td>
								<%=poolDef.getMinimumConnectionCount()%>
							</td>
						</tr>
						<tr>
							<th>
								最大连接数:
							</th>
							<td>
								<%=poolDef.getMaximumConnectionCount()%>
							</td>
						</tr>
						<tr>
							<th>
								测试语句:
							</th>
							<td>
								<%=poolDef.getHouseKeepingTestSql()%>
							</td>
						</tr>
						<tr>
							<th>
								使用前测试:
							</th>
							<td>
								<%=(poolDef.isTestBeforeUse() ? "是" : "否")%>
							</td>
						</tr>
						<tr>
							<th>
								使用后测试:
							</th>
							<td>
								<%=(poolDef.isTestAfterUse() ? "是" : "否")%>
							</td>
						</tr>
						<tr>
							<th>
								连接:
							</th>
							<td>
							    <strong>
								<%=poolStats.getActiveConnectionCount()%>
								(使用),
								<%=poolStats.getAvailableConnectionCount()%>
								(空闲),
								<%=poolStats.getMaximumConnectionCount()%>
								(最大)
								</strong>
								<br />
								<table class="table">
									<tr>
										<%
											if (active > 0) {
										%>
										<td
											style="border: 1.0px solid #000000; background-color: #ffffaa"
											width="<%=active%>%">
											&nbsp;
										</td>
										<%
											}
										%>
										<%
											if (inactive > 0) {
										%>
										<td
											style="border: 1.0px solid #000000; background-color: #aaffaa"
											width="<%=inactive%>%">
											&nbsp;
										</td>
										<%
											}
										%>
										<td
											style="border: 1.0px solid #000000; background-color: #eeeeee"
											width="<%=notopened%>%">
											&nbsp;
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<th>
								Connections Served:
							</th>
							<td>
								<%=poolStats.getServedCount()%>
							</td>
						</tr>
						<tr>
							<th>
								Connections Refused:
							</th>
							<td>
								<%=poolStats.getRefusedCount()%>
							</td>
						</tr>
					</tbody>
				</table>
				<table class="table  table-bordered  table-condensed">
					<thead>
						<tr>
							<th>
								编号
							</th>
							<th>
								创建时间
							</th>
							<th>
								最后使用时间
							</th>
							<th>
								线程
							</th>
						</tr>
					</thead>
					<tbody>
						<%
							for (ConnectionInfoIF info : poolStats.getConnectionInfos()) {
						%>
						<tr>
							<td>
								<span class="badge badge-info"><%=info.getId()%></span>
							</td>
							<td><%=dateFormat.format(info.getBirthDate())%></td>
							<td>
								<%=info.getTimeLastStartActive() > 0 ? dateFormat.format(new java.util.Date(info
								.getTimeLastStartActive())) : "-"%>
							</td>
							<td><%=info.getRequester() != null ? info.getRequester() : "-"%></td>
						</tr>
						<%
							}
						%>
					</tbody>
				</table>
			</fieldset>
			<%
				} catch (Exception e) {
						webManager.logEvent("显示系统连接池时发生错误", e.getMessage());
					}
				}
			%>
		</div>
	</body>